package indi.cloud.common.elasticsearch.core;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class EsResult<T> extends EsBaseResp {
    private T data;
    private Long pageCount;
    private Long recordCount;

    public void setPageCount(Long recordCount, Long size) {
        this.pageCount = recordCount / size;
    }

    public static <T> EsResult<T> of(T t) {
        return EsResult.of(t, null, null, null);
    }

    public static <T> EsResult<T> of(T t, Long recordCount) {
        return EsResult.of(t, recordCount, null, null);
    }

    public static <T> EsResult<T> of(T t, Long recordCount, Long pageCount) {
        return EsResult.of(t, pageCount, recordCount, null);
    }

    public static <T> EsResult<T> of(T t, Long recordCount, Long pageCount, Long pageSize) {
        EsResult<T> esResult = new EsResult<>();
        esResult.setData(t);
        if (recordCount != null) {
            esResult.setRecordCount(recordCount);
        }
        if (pageCount != null) {
            esResult.setPageCount(pageCount);
        }
        if (pageSize != null) {
            esResult.setPageCount(recordCount, pageSize);
        }
        return esResult;
    }
}
